package com.union.core.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.union.core.sys.service.SysService;

public abstract class BaseAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = -8964333226680426960L;

	protected SysService sysService = SysService.getInstance();
	
	//分页
	protected int start;
	protected int intPageSize = 15;
	protected int page = 1;      //页码
	protected int intRowCount;   //总行数
	protected int intPageCount;  //总页数
	protected int intPage;       //页数变量

	public final static String TEMPLATE_DIR = "template";

	/**
	 * 提示消息
	 */
	private String msgInfo = null;

	/**
	 * @param msgInfo the msgInfo to set
	 */
	public void setMsgInfo(String msgInfo) {
		this.msgInfo = msgInfo;
	}

	/**
	 * @return the msgInfo
	 */
	public String getMsgInfo() {
		return msgInfo;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getIntPageSize() {
		return intPageSize;
	}

	public void setIntPageSize(int intPageSize) {
		this.intPageSize = intPageSize;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getIntRowCount() {
		return intRowCount;
	}

	public void setIntRowCount(int intRowCount) {
		this.intRowCount = intRowCount;
	}

	public int getIntPageCount() {
		return intPageCount;
	}

	public void setIntPageCount(int intPageCount) {
		this.intPageCount = intPageCount;
	}

	public int getIntPage() {
		return intPage;
	}

	public void setIntPage(int intPage) {
		this.intPage = intPage;
	}
	
	public void calPage(){
		intPageCount = (intRowCount + intPageSize -1)/intPageSize;
		if(page<1){
			page = 1;
			intPage = 1;
		}else{
			intPage = page;
		}
		if(intPage > intPageCount) intPage = intPageCount;	
		if(intPageCount>0){
			start = (intPage-1) * intPageSize;
		}
	}
	
	public HttpServletRequest getRequest(){
		return ServletActionContext.getRequest();
	}
	
	public HttpServletResponse getResponse(){
		return ServletActionContext.getResponse();
	}
	
	public String getTemplatePath(){
		return ServletActionContext.getServletContext().getRealPath("/") + TEMPLATE_DIR + "/";
	}
	
	public String getTempPath(){
		return ServletActionContext.getServletContext().getRealPath("/") + "temp/";
	}
	
	public String getRealPath(){
		return ServletActionContext.getServletContext().getRealPath("/");
	}
}
